﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Test
{
    public partial class TgaImageForm : Form
    {
        public TgaImageForm()
        {
            InitializeComponent();
        }

        private void ViewImageForm_Load(object sender, EventArgs e)
        {
            string dir = @"../../data/";
            listBox1.Items.AddRange((
                from f in (new DirectoryInfo(dir)).GetFiles("*.tga")
                select f.Name).ToArray());

            string filename = @"../../data/earth.tga";
            Util.Media.TgaImage img = new Util.Media.TgaImage(filename);
            pictureBox1.Image = img.Image;
            propertyGrid1.SelectedObject = img;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                string filename = @"../../data/" + listBox1.SelectedItem.ToString();
                Util.Media.TgaImage img = new Util.Media.TgaImage(filename);
                pictureBox1.Image = img.Image;
                propertyGrid1.SelectedObject = img;
            }
        }

        private void btnSaveImage_Click(object sender, EventArgs e)
        {
            Image img = pictureBox1.Image;
            if (img != null)
            {
                img.Save("test.gif", ImageFormat.Gif);
            }
        }
    }
}
